#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: cleanpyc.py

"""
http://amix.dk/blog/viewEntry/79
Clean .pyc files
"""
import os, sys

def pyc_clean(dir):
    findcmd = 'find %s -name "*.pyc" -print' % dir
    count = 0
    for f in os.popen(findcmd).readlines():
        count += 1
        os.remove(str(f[:-1]))
    print "Removed %d .pyc files" % count 

def bak_clean(dir):
    findcmd = 'find %s -name "*.*~" -print' % dir
    count = 0
    for f in os.popen(findcmd).readlines():
        count += 1
        os.remove(str(f[:-1]))
    print "Removed %d .~ files" % count

def egg_clean(dir):
    findcmd = 'find %s -name ".svn" -print' % dir
    count = 0
    for f in os.popen(findcmd).readlines():
        count += 1
        rmdir = "rm -rf %s" % f
        os.popen(rmdir)
    print "Removed %d .egg-* files" % count 


def mdb_clean():
    os.chdir("./metadata")
    rmdir = "rm -rf *"
    os.popen(rmdir)
    print "Removed metadata"
   
def mo_clean():
    rmdir = "rm -rf mo"
    os.popen(rmdir)
    print "Removed mo files"

if __name__ == "__main__":    
    pyc_clean(".")
    egg_clean(".")
    bak_clean(".")
    mo_clean()
